package com.shanghaionstar.activity.webview.handler.picture;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ImportImagesData
{
    public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 日期格式
    
    private List<ImportImageItem> list;
    
    private Map<String, List<ImportImageItem>> map;
    
    private HashMap<String, Boolean> headRecord = new HashMap<String, Boolean>();// 头部信息记录表
    
    public ImportImagesData(List<ImageDetailBean> srcList, HashMap<String, String> hasUploadMap)
    {
        try
        {
            Collections.sort(srcList, new Comparator<ImageDetailBean>()
            {// 排序
                @Override
                public int compare(ImageDetailBean lhs, ImageDetailBean rhs)
                {
                    return lhs.getDateTaken() >= rhs.getDateTaken() ? -1 : 1;
                }
            });
        }
        catch (Exception e)
        {
        }
        
        list = new ArrayList<ImportImageItem>(srcList.size());
        map = new HashMap<String, List<ImportImageItem>>();
        
        for (int i = 0, size = srcList.size(); i < size; i++)
        {
            ImportImageItem listItem = genFromSrc(srcList.get(i));// 数据存入bean
            
            Date date = new Date(listItem.getDateTaken());// 时间数据转换
            String timeStr = sdf.format(date);
            listItem.timeStr = (timeStr);
            list.add(listItem);
            
            // map中放入数据
            List<ImportImageItem> mapList = map.get(timeStr);
            if (mapList != null)
            {// map中已有值
                mapList.add(listItem);
            }
            else
            {// 新建List
                mapList = new ArrayList<ImportImageItem>();
                mapList.add(listItem);
                map.put(timeStr, mapList);
                
                headRecord.put(timeStr, false);
            }
        } // end for i
        
    }
    
    /**
     * 复制数据
     * 
     * @param srcData
     * @return
     */
    private ImportImageItem genFromSrc(ImageDetailBean srcData)
    {
        ImportImageItem listItem = new ImportImageItem();
        listItem.setImage(srcData.getImage());
        listItem.setTime(srcData.getTime());
        listItem.setSize(srcData.getSize());
        listItem.setDateTaken(srcData.getDateTaken());
        return listItem;
    }
    
    public List<ImportImageItem> getList()
    {
        return list;
    }
    
    public void setList(List<ImportImageItem> list)
    {
        this.list = list;
    }
    
    public Map<String, List<ImportImageItem>> getMap()
    {
        return map;
    }
    
    public void setMap(Map<String, List<ImportImageItem>> map)
    {
        this.map = map;
    }
    
    public HashMap<String, Boolean> getHeadRecord()
    {
        return headRecord;
    }
    
    public void setHeadRecord(HashMap<String, Boolean> headRecord)
    {
        this.headRecord = headRecord;
    }
}// end class
